#!/usr/bin/perl

##  --------------------------------------------------------
##                       use/require
##  --------------------------------------------------------

use strict;
use warnings;

use File::Basename;
use WWW::Mechanize;



##  --------------------------------------------------------
##                         constants
##  --------------------------------------------------------

use constant
{
  YubicoAuthSrvURLprefix  =>  'http://api.yubico.com/wsapi/verify?id='
};



##  --------------------------------------------------------
##                 function  ::  usage
##  --------------------------------------------------------
##
##  sig  ::  (void|errMsg:str)  --->  void

sub usage(;$)
{
  print "\n\n!!!  @_\n\n" if @_;
  my $prog = basename $0;

  print <<_USAGE_END;

Usage:
    $prog  clientID  oneTimePasscode

_USAGE_END
}



##  --------------------------------------------------------
##                     main program
##  --------------------------------------------------------

if (@ARGV != 2) { usage and exit 2 }
my $YubicoAuthSrvURL = YubicoAuthSrvURLprefix . $ARGV[0] . "&otp=" . $ARGV[1];
my $mech = WWW::Mechanize->new();
$mech->get($YubicoAuthSrvURL);
my $YubicoAuthSrvResponse = $mech->response()->content();

if ($YubicoAuthSrvResponse =~ /status=OK/) { print "OTP verification ok\n" }
else { print "OTP verification failed\n" }


